package com.xce.business.service.impl;

import com.xce.business.feign.OrderTblFeign;
import com.xce.business.feign.StorageFeign;
import com.xce.business.service.BusinessService;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName BusinessServiceImpl
 * @Description TODO
 * @Author lld
 * @Date 2025/7/10 1:04
 * @Version 1.0
 */
@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private OrderTblFeign orderTblFeign;

    @Autowired
    private StorageFeign storageFeign;

    @Override
    @GlobalTransactional
    public void purchase(String userId, String commodityCode, int orderCount) {

        // TODO 1.扣减库存
        storageFeign.deduct(commodityCode, orderCount);
        // TODO 2.创建订单
        orderTblFeign.create(userId, commodityCode, orderCount);
    }
}
